package com.katze.boot.file.registry;

import com.katze.boot.file.DirectoryEnum;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * 管理所有文件上传实例
 */
public class FileSystemRegistrationBean {

    private final Map<String, FileSystemHandler> beans = new HashMap<>();

    public FileSystemHandler get(String name) {
        return Optional.ofNullable(this.beans.get(name)).orElseThrow(() -> new NullPointerException(name + "服务尚未注册"));
    }

    public void registration(FileSystemHandler bean, DirectoryEnum... name) {
        for (DirectoryEnum item : name) {
            this.beans.put(item.code(), bean);
        }
    }
}
